package com.example.fangyh09.listview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    ListView listview;
    ArrayAdapter<String> arr_adapter;
    SimpleAdapter simp_adapter;
    List<Map<String,Object>> list;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        listview = (ListView)findViewById(R.id.listView);
        String []data = {"sun","sand"};
        list = new ArrayList<Map<String,Object>>();
        arr_adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,data);
        simp_adapter = new SimpleAdapter(this,getData(),R.layout.item,new String[]{"pic","text"},new int[]{R.id.pic,R.id.text});
        listview.setAdapter(simp_adapter);
    }
    private List<Map<String,Object>> getData() {
        for (int i = 0;i < 20;i ++) {
            Map<String,Object> mp = new HashMap<String,Object>();
            mp.put("pic",R.drawable.pic);
            mp.put("text","test" + i);
            list.add(mp);
        }
        return list;
    }
}




































